{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# \ud83d\udcdd Exercise M7.03\n",
    "\n",
    "As with the classification metrics exercise, we will evaluate the regression\n",
    "metrics within a cross-validation framework to get familiar with the syntax.\n",
    "\n",
    "We will use the Ames house prices dataset."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "ames_housing = pd.read_csv(\"../datasets/house_prices.csv\")\n",
    "data = ames_housing.drop(columns=\"SalePrice\")\n",
    "target = ames_housing[\"SalePrice\"]\n",
    "data = data.select_dtypes(np.number)\n",
    "target /= 1000"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "lines_to_next_cell": 2
   },
   "source": [
    "<div class=\"admonition note alert alert-info\">\n",
    "<p class=\"first admonition-title\" style=\"font-weight: bold;\">Note</p>\n",
    "<p class=\"last\">If you want a deeper overview regarding this dataset, you can refer to the\n",
    "Appendix - Datasets description section at the end of this MOOC.</p>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The first step will be to create a linear regression model."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Write your code here."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Then, use the `cross_val_score` to estimate the generalization performance of\n",
    "the model. Use a `KFold` cross-validation with 10 folds. Make the use of the\n",
    "$R^2$ score explicit by assigning the parameter `scoring` (even though it is\n",
    "the default score)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Write your code here."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Then, instead of using the $R^2$ score, use the mean absolute error (MAE). You\n",
    "may need to refer to the documentation for the `scoring` parameter."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Write your code here."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Finally, use the `cross_validate` function and compute multiple scores/errors\n",
    "at once by passing a list of scorers to the `scoring` parameter. You can\n",
    "compute the $R^2$ score and the mean absolute error for instance."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Write your code here."
   ]
  }
 ],
 "metadata": {
  "jupytext": {
   "main_language": "python"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}